package org.df.ulab.bot.engine;

import java.util.ArrayList;
import java.util.List;

import org.df.ulab.bot.api.command.Command;
import org.df.ulab.bot.api.communication.CommunicationService;
import org.df.ulab.bot.api.message.Message;
import org.df.ulab.bot.api.message.MessageHandler;
import org.df.ulab.bot.engine.commands.Abort;
import org.df.ulab.bot.engine.commands.StartHandler;
import org.df.ulab.bot.engine.commands.StopHandler;
import org.df.ulab.bot.engine.commands.SystemStatus;
import org.df.ulab.bot.util.message.SimpleMsgInterpreter;

/**
 * @author Daniel Filgueiras
 * 04/05/2011
 */
public class CoreHandler implements MessageHandler {

	private List<Class<? extends Command>> cmdClasses = new ArrayList<Class<? extends Command>>();
	
	public CoreHandler() {
		cmdClasses.add(Abort.class);
		cmdClasses.add(StartHandler.class);
		cmdClasses.add(StopHandler.class);
		cmdClasses.add(SystemStatus.class);
	}
	
	@Override
	public void init(CommunicationService service) {
		return;
	}
	
	@Override
	public void close() {
	}
	
	@Override
	public boolean handle(Message message) {
		
		Command command = SimpleMsgInterpreter.getCommand(message, cmdClasses);
		
		if (command != null) {
			return command.proccess(message);
		}
		
		return false;
	}
}
